<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between">
				<view class="flex align-center">
					<image @click="handleToAvatar" :src="avatar" class="cu-avatar xl round" mode="widthFix">
					</image>
					<view class="user-info">
						<view class="u_title">
							<span>{{ name }}</span>
							<span class="vipLevel" v-bind:class="{ noVip: isNoVip }">VIP{{user.vip}}</span>
						</view>
						<view class="u_title" style="font-size: 14px;">
							ID：{{ userId }}
						</view>

					</view>
				</view>

			</view>
		</view>

		<view class="content-section">
			<view class="flex align-center justify-around " style="color: white;">
				<view>
					<view class="amount">{{user.amount}}
					</view>
					<view class="title ">{{$t('mine.balance')}}</view>
				</view>
				<view>
					<view class="amount">{{user.team}}
					</view>
					<view class="title ">{{$t('mine.teamBalance')}}</view>
				</view>
				<view>
					<view class="amount">{{user.integral}}
					</view>
					<view class="title ">{{$t('mine.point')}}</view>
				</view>
			</view>
			<view class="mine-actions grid col-3 text-center">
				<view class="action-item" @click="rechargeShow()">
					<uni-icons type="download" size="34" color="#F6DDA4"></uni-icons>
					<text class="text">{{$t('mine.recharge')}}</text>
				</view>
				<view class="action-item" @click="withdrawalShow">
					<uni-icons type="upload" size="34" color="#F6DDA4"></uni-icons>
					<!-- <view class="iconfont icon-service text-blue icon"></view> -->
					<text class="text">{{$t('mine.withdrawal')}}</text>
				</view>
				<view class="action-item" @click="signShowFun()">
					<uni-icons type="calendar-filled" size="34" :color="user.signed =='1'?'#F6DDA4':'gray'"></uni-icons>
					<!-- <view class="iconfont icon-service text-blue icon"></view> -->
					<text class="text">{{$t('mine.signIn')}}</text>
				</view>
			</view>

			<view class="menu-list">
				<view class="list-cell list-cell-arrow" style="padding-top: 8px; padding-bottom: 8px;">
					<view class="menu-item-box flex justify-between">
						<view class="flex justify-start ">
							<u-icon size="18" name="download" color="#F6DDA4"></u-icon>
							<view style="margin-left: 5px">app {{$t('mine.download')}}</view>
						</view>
						<view><button class="mini-btn down-btn" type="primary" size="mini"
								@click="downLoad">Download</button></view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" style="padding-top: 8px; padding-bottom: 8px;">
					<view class="menu-item-box flex justify-between">
						<view class="flex justify-start ">
							<u-icon size="17" name="kefu-ermai" color="#F6DDA4"></u-icon>
							<view style="margin-left: 5px">{{$t('mine.contactConsultant')}} </view>
						</view>
						<view class="flex  justify-start align-center">
							<span>{{user.mobile}}</span>
							<button class="mini-btn copy-btn" type="primary" size="mini"
								@click="copyMobile">{{$t('common.copy')}}</button>
						</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="showBankCard()">
					<view class="menu-item-box">
						<!-- <view class="iconfont icon-code menu-icon"></view> -->
						<uni-icons type="map-filled" size="16" color="#F6DDA4"></uni-icons>
						<view style="margin-left: 5px">{{$t('mine.bankManage')}}</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="showWithdralRecord()">
					<view class="menu-item-box">
						<u-icon size="18" name="order" color="#F6DDA4"></u-icon>
						<view style="margin-left: 5px">{{$t('mine.withdrawalReward')}}</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="showTeamReward()">
					<view class=" menu-item-box">
						<u-icon size="18" name="order" color="#F6DDA4"></u-icon>
						<view style="margin-left: 5px">{{$t('mine.teamRewardRecord')}}</view>
					</view>
				</view>
				<view class="list-cell list-cell-arrow" @click="showTerminalRecord()">
					<view class="menu-item-box">
						<u-icon size="18" name="order" color="#F6DDA4"></u-icon>
						<view style="margin-left: 5px">{{$t('mine.minerRewardRecord')}}</view>
					</view>
				</view>
				<!-- <view class="list-cell list-cell-arrow" @click="showIntegralRecord()">
					<view class="menu-item-box">
						<view class="iconfont icon-code menu-icon"></view>
						<view>积分记录</view>
					</view>
				</view> -->
				<view class="list-cell list-cell-arrow" @click="handleToSetting()">
					<view class="menu-item-box">
						<u-icon size="17" name="setting" color="#F6DDA4"></u-icon>
						<view style="margin-left: 5px">{{$t('mine.setting')}}</view>
					</view>
				</view>



			</view>



			<u-popup :show="signShow" mode="center" @close="signClose" customStyle="border-radius: 10px;
						width: 85%;
						max-height: 550px;
						max-width: 350px;">
				<view class="signs-content">
					<span class="titleBox">Weekly sign-in</span>
					<view class="signContent">
						<view class="basic " :class="user.signDay<item.dictValue ? 'signWqd' : 'signYqd'"
							v-for="item in signList">
							<span class="itemTitle"> {{item.dictValue}} {{$t('common.day')}} </span>
							<view class="qdImg">
								<image
									src=""
									style="width: 46px; height: 30px; border-radius: 0px; overflow: visible; background-color: transparent;">
								</image>
							</view>
							<view class="qdImgText scoreSpan " :class="user.signDay<item.dictValue ? 'yellow' : ''">
								1point
							</view>
						</view>
					</view>

					<button class="sign-btn" type="primary" @click="sign()">{{$t('mine.signIn')}}</button>
					<view class="close-sign" @click="signClose">
						<image style="width: 30px; height: 30px; border-radius: 0px; overflow: visible;"
							src="">
						</image>
					</view>
				</view>
			</u-popup>


		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import {
		dictType,
		getMineInfo,
		getBalanceInfo,
		userSign
	} from "@/api/system/user.js"


	export default {
		data() {
			return {
				userId: this.$store.state.user.userId,
				name: this.$store.state.user.name,
				user: {},
				version: getApp().globalData.config.appInfo.version,
				isNoVip: true,
				isWindows: false,
				signShow: false,
				signList: [],
				signDay: '1'
			}
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		onShow() {
			uni.setTabBarItem({
				index: 4,
				visible: false
			})
			this.getBalanceInfoFun();
		},
		onLoad: function() {
			this.isWindows = uni.getSystemInfoSync().platform == 'windows';

			dictType("sign_point_period").then(rsp => {
				if (rsp.code == 200) {
					this.signList = rsp.data;
				}
			})
		},
		methods: {
			getBalanceInfoFun() {
				getMineInfo().then(rsp => {
					if (rsp.code == 200) {
						this.user = rsp.data;
						if (rsp.data.vip > 0) {
							this.isNoVip = false;
						}
					}
				});
			},
			signShowFun() {
				if (this.user.signed == '1') {
					uni.showToast({
						title: this.$t('mine.signedIn'),
						icon: 'error'
					})
				} else {
					this.signShow = true;
				}
			},
			downLoad() {
				//#ifdef H5
				window.open(this.user.url);
				//#endif

			},
			copyMobile() {
				uni.setClipboardData({
					data: this.user.mobile,
					success() {
						uni.showToast({
							title: this.$t('common.copySuccess')
						});
					}
				});
			},
			signClose() {
				this.signShow = false;
			},
			sign() {
				userSign().then(rsp => {
					if (rsp.code == 200) {
						uni.showToast({
							title: this.$t('mine.signSuccess'),
							icon: 'success'
						})
						this.signShow = false;
						this.getBalanceInfoFun();

					} else {
						uni.showToast({
							title: rsp.msg,
							icon: 'error'
						})
					}
				})
			},
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleLogout() {
				this.$modal.confirm(this.$t('mine.outSystem')).then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			handleHelp() {

			},
			handleAbout() {
				this.$tab.navigateTo('/pages/mine/about/index')
			},
			rechargeShow() {
				this.$tab.navigateTo('/pages/mine/recharge/recharge')
			},
			withdrawalShow() {
				this.$tab.navigateTo('/pages/mine/withdrawal/withdrawal')
			},
			showBankCard() {
				this.$tab.navigateTo('/pages/mine/card/card')
			},
			showWithdralRecord() {
				this.$tab.navigateTo('/pages/mine/withdrawal/withdrawal-record')
			},
			showTeamReward() {
				this.$tab.navigateTo('/pages/mine/record/team-reward-record')
			},
			showTerminalRecord() {
				this.$tab.navigateTo('/pages/mine/record/terminal-reward-record')
			},
			showIntegralRecord() {
				this.$tab.navigateTo('/pages/mine/record/integral-record')
			},

		}
	}
</script>

<style lang="scss">
	page {
		background-color: $uni-color-bg;
		color: $uni-color-font;
	}

	.mine-container {
		width: 100%;
		height: 100%;
		padding-bottom: 50px;

		.down-btn {
			background-color: $uni-color-primary;
			color: $uni-color-box;
			border-radius: 15px;
		}

		.copy-btn {
			margin-left: 10px;
			background-color: $uni-color-primary;
			color: $uni-color-box;
			border-radius: 15px;
		}

		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: $uni-color-box;
			color: white;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 2px solid #eaeaea;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;

					.vipLevel {
						margin-left: 12px;
						color: #eaa02a;
						padding: 0 10px;
						font-weight: 500;
						font-size: 14px;
						height: 20px;
						background: linear-gradient(90deg, #fff4c1, #fae096);
						border-radius: 13px 13px 13px 13px;
					}

					.noVip {
						color: gray;
						background: linear-gradient(90deg, #e2d8d8, #e2d8d8);
					}
				}
			}
		}

		.content-section {
			position: relative;
			top: -50px;

			.amount {
				font-size: 18px;
				font-family: PingFang SC-Semibold, PingFang SC;
				font-weight: 600;
				text-align: center;
			}

			.title {
				font-size: 12px;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				text-align: center;
			}

			.mine-actions {
				margin: 15px 15px;
				padding: 5px 0px;
				border-radius: 8px;
				background-color: $uni-color-box;

				.action-item {
					.icon {
						font-size: 28px;

					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}

			.menu-list {

				.list-cell {
					background-color: $uni-color-box;
					color: $uni-color-font;
				}
			}
		}

		.signs-content {
			padding: 20px 17px 26px;

			.titleBox {
				display: flex;
				justify-content: space-around;
				text-align: center;
				font-size: 22px;
				font-weight: 700;
				margin-bottom: 20px;
			}

			.signContent {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;


				.basic {
					background-repeat: no-repeat;
					background-size: 100% 100%;
					height: 80px;
					color: #fff;
					width: 22%;
					margin-bottom: 16px;
				}

				.signYqd {
					background-image: url();
					color: #fffb7c;
				}

				.signWqd {
					background-image: url();
				}

				.itemTitle {
					height: 20px;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 12px;
					font-weight: 500;
				}

				.qdImg {
					margin-top: 6px;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.qdImgText {
					color: #fff;
					font-size: 12px;
					font-weight: 500;
					margin-top: 4px;
					display: flex;
					justify-content: center;
					align-items: center;
				}

				.yellow {
					color: #f7651d;
				}

			}

			.sign-btn {
				height: 42px;
				background-color: $uni-color-primary;
				color: black;
				border-radius: 15px;
				border-width: 0px;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.close-sign {
				position: absolute;
				bottom: -50px;
				left: 50%;
				-webkit-transform: translateX(-50%);
				transform: translateX(-50%);
				overflow: visible;
				background-color: transparent;
				width: 30px;
				height: 30px;
			}


		}

	}
</style>